<template>
  <el-dialog :title="title" :visible.sync="dialogFormVisible" @close="close">
    <el-form ref="form" :model="form" :rules="rules" :inline="true" :label-position="labelPosition" label-width="200px">
      <el-form-item label="费用号" prop="costNumber">
        <el-input v-model.trim="form.costNumber" autocomplete="off" />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input v-model.trim="form.projectName" autocomplete="off" />
      </el-form-item>
      <el-form-item label="年限" prop="year">
        <el-date-picker v-model="form.year" type="year" placeholder="选择年"></el-date-picker>
      </el-form-item>
      <el-form-item label="项目地区" prop="area">
        <el-input v-model.trim="form.area" autocomplete="off" />
      </el-form-item>
      <el-form-item label="设备类型" prop="deviceType">
        <el-input v-model.trim="form.deviceType" autocomplete="off" />
      </el-form-item>
      <el-form-item label="驱动箱类型" prop="driveBoxType">
        <el-input v-model.trim="form.driveBoxType" autocomplete="off" />
      </el-form-item>
      <el-form-item label="设备数量" prop="devicesNumber">
        <el-input v-model.trim="form.devicesNumber" autocomplete="off" />
      </el-form-item>

      <el-form-item label="单台治具数量/通道" prop="fixturesChannels">
        <el-input v-model.trim="form.fixturesChannels" autocomplete="off" />
      </el-form-item>
      <el-form-item label="项目担当" prop="projectManager">
        <el-input v-model.trim="form.projectManager" autocomplete="off" />
      </el-form-item>
      <el-form-item label="软件负责人" prop="devicesNumber">
        <el-input v-model.trim="form.devicesNumber" autocomplete="off" />
      </el-form-item>
      <el-form-item label="充放电负责人" prop="devicesNumber">
        <el-input v-model.trim="form.devicesNumber" autocomplete="off" />
      </el-form-item>
      <el-form-item label="视觉负责人" prop="devicesNumber">
        <el-input v-model.trim="form.devicesNumber" autocomplete="off" />
      </el-form-item>
      <el-form-item label="厂内项目目前情况" prop="devicesNumber">
        <el-input v-model.trim="form.devicesNumber" autocomplete="off" />
      </el-form-item>
      <el-form-item label="现场客户现场情况" prop="devicesNumber">
        <el-input v-model.trim="form.devicesNumber" autocomplete="off" />
      </el-form-item>
      <el-form-item label="厂内FAT时间" prop="devicesNumber">
        <el-input v-model.trim="form.devicesNumber" autocomplete="off" />
      </el-form-item>
      <el-form-item label="厂内FAT时间" prop="devicesNumber">
        <el-input v-model.trim="form.devicesNumber" autocomplete="off" />
      </el-form-item>
      <el-form-item label="厂内FAT时间" prop="devicesNumber">
        <el-input v-model.trim="form.devicesNumber" autocomplete="off" />
      </el-form-item>

      <el-form-item label=" 备注" prop="remarks">
        <el-input type="textarea" v-model="form.remarks"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { insertProject, updateProject } from '@/api/wordOrder'

  export default {
    name: 'TableEdit',
    data() {
      return {
        form: {
          costNumber: '',
          projectName: '',
        },
        rules: {
          costNumber: [{ required: true, trigger: 'blur', message: '请输入费用号' }],
          projectName: [{ required: true, trigger: 'blur', message: '请输入项目名称' }],
        },
        title: '',
        dialogFormVisible: false,
      }
    },
    created() {},
    methods: {
      showEdit(row) {
        if (!row) {
          this.title = '新增项目信息'
        } else {
          this.title = '编辑项目信息'
          this.form = Object.assign({}, row)
        }
        this.dialogFormVisible = true
      },
      close() {
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        this.dialogFormVisible = false
        this.$emit('refreshTable')
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            if (this.form.id) {
              await updateProject(this.form)
            } else {
              await insertProject(this.form)
            }
            this.$baseMessage('提交成功', 'success')
            this.$refs['form'].resetFields()
            this.dialogFormVisible = false
            this.$emit('refreshTable')
            this.form = this.$options.data().form
          } else {
            return false
          }
        })
      },
    },
  }
</script>
